Find the Duplicate Number
Question
com
Given an array of integers, find the single duplicate number in the array and return its value.
Example 1
Input: [2, 3, 1, 5, 4, 3]
Output: 3
Solution
- ▭
- ▯
all//Find the Duplicate Number.py
def find_duplicate_number(arr):
seen = set()
for num in arr:
if num in seen:
return num
else:
seen.add(num)
return -1
all//Find the Duplicate Number.py
def find_duplicate_number(arr):
seen = set()
for num in arr:
if num in seen:
return num
else:
seen.add(num)
return -1